//
//  LZCompanyInfoViewController.m
//  laziz_Merchant
//
//  Created by ZhaoDongBo on 2016/12/15.
//  Copyright © 2016年 XBN. All rights reserved.
//

#import "LZCompanyInfoViewController.h"
#import "LZMyCompanyInfoTableView.h"
#import "Masonry.h"

#import "GVUserDefaults+LZProperties.h"
#import "LZUserModel.h"
#import "MJPhotoBrowser.h"

@interface LZCompanyInfoViewController ()

@property (nonatomic, strong) LZMyCompanyInfoTableView * tableView;
@property (nonatomic, strong) LZMerchantInfoModel * merchantInfo;

@end

@implementation LZCompanyInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.umLogPageViewName = @"公司信息页面";
    self.title = LZLocalizedString(@"company_info", nil);
    self.view.backgroundColor = UIColorFromRGB(0xf9f7f7, 1);
    self.merchantInfo =  [LZUserModel Instance].merchantInfo;
    
    [self configViews];
}

- (void)configViews {
    [self.view addSubview:self.tableView];
    [self.tableView makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.leading.mas_equalTo(0);
        make.trailing.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
    }];
}

- (void)navbarBackButtonClickAction:(UIButton*)sender {
    
    [self.navigationController popViewControllerAnimated:YES];
}

- (LZMyCompanyInfoTableView *)tableView {

    WS(weakSelf);
    if (_tableView == nil) {
        _tableView = [[LZMyCompanyInfoTableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _tableView.merchantInfoModel = self.merchantInfo;
        _tableView.didTapImageBlock = ^(UITapGestureRecognizer * tapGR) {
            [weakSelf photoTap:tapGR];
        };
    }
    
    return _tableView;
}

//点击预览图片
- (void)photoTap:(UITapGestureRecognizer *)recognizer
{
    //1.创建图片浏览器
    MJPhotoBrowser *brower = [[MJPhotoBrowser alloc] init];
    
    //2.告诉图片浏览器显示所有的图片
    NSMutableArray *photos = [NSMutableArray array];
    
    MJPhoto *photo = [[MJPhoto alloc] init];
    photo.url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@", APIBaseImageUrl, self.merchantInfo.licencePhoto]];
    photo.srcImageView = (UIImageView*)recognizer.view; //设置来源哪一个UIImageView
    [photos addObject:photo];
    
    brower.photos = photos;
    
    //3.设置默认显示的图片索引
    brower.currentPhotoIndex = recognizer.view.tag;
    
    //4.显示浏览器
    [brower show];
}

@end
